package com.leather.question.vo;

import com.leather.common.entity.Question;
import com.leather.common.result.CodeMsg;
import com.leather.common.result.Result;
import com.leather.common.toolkits.DateKit;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
public class QuestionAddVo implements Serializable {

    private Integer id;

    private String questionTitle;

    private String questionDesc;

    private String questionImgUrl;

    private Integer userId;


    private Question transfer(){
        Question question = new Question();
        question.setId(0);
        question.setQuestionTitle(questionTitle);
        question.setQuestionDesc(questionDesc);
        question.setQuestionImgUrl(questionImgUrl);
        question.setCreateTime(DateKit.now());
        question.setStars(0);
        question.setAnswers(0);
        question.setUserId(userId);
        return question;
    }

    public Result validate(){

        if(StringUtils.isBlank(questionTitle)) {
            return Result.error(CodeMsg.EMPTY_QUESTION_TITLE);
        }
        if(StringUtils.isBlank(questionDesc)) {
            return Result.error(CodeMsg.EMPTY_QUESTION_DESC);
        }
        if(userId==null||userId<=0){
            return Result.error(CodeMsg.ERROR_USER_ID);
        }
        return Result.success(transfer());
    }

}
